﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Yjb_model : MonoBehaviour, IPointerDownHandler
{
    public Vector3 camPos0;
    public Vector3 camRot0;
    public Yj_model yj;
    public void OnPointerDown(PointerEventData eventData)
    {
        // Debug.Log("点击"+gameObject.name); 
        if (Input.GetMouseButtonDown(0))
        {
            StartCoroutine(MoveToPosition());
        }
        
       
    }

    // Use this for initialization
    void Start()
    {
        YjbInit();  
    }

    void YjbInit() {
        //获得相机初始位置
        //GameObject mainCam = GameObject.Find("Main Camera");
        //camPos0 = mainCam.transform.position;
        //camRot0 = mainCam.transform.eulerAngles;
        GameObject go = transform.parent.parent.gameObject;
        //Debug.Log("objname:"+go.name);
        yj = (Yj_model)go.GetComponent(typeof(Yj_model));
    }
    // Update is called once per frame
    void Update () {
		
	}

    IEnumerator MoveToPosition()
    {
        GameObject maincam = GameObject.Find("Main Camera");
        Vector3 target = Init.camPos0;
        maincam.transform.rotation = Quaternion.Euler(0,0,0); //设置摄像机rotation回原点
        while (maincam.transform.position != target)
        {
            
            maincam.transform.position = Vector3.MoveTowards(maincam.transform.position, target, 10 * Time.deltaTime);           
            yield return 0;
        }
        yj.yja.SetActive(true);
        transform.parent.gameObject.SetActive(false);
        
    }

}
